<script type="text/javascript" src="{lib file=mobile/goodsinfo.js}" charset="utf-8"></script>
<script type="text/javascript">
//<!CDATA[
/* buy */
function buy()
{
    if (goodsspec.getSpec() == null)
    {
        alert(lang.select_specs);
        return;
    }
    var spec_id = goodsspec.getSpec().id;

    var quantity = $("#quantity").val();
    if (quantity == '')
    {
        alert(lang.input_quantity);
        return;
    }
    if (parseInt(quantity) < 1 || isNaN(quantity))
    {
        alert(lang.invalid_quantity);
        return;
    }

    add_to_cart(spec_id, quantity);
}

/* add cart */
function add_to_cart(spec_id, quantity)
{
    var url = REAL_SITE_URL + '/index.php?app=cart&act=add';
    $.getJSON(url, {'spec_id':spec_id, 'quantity':quantity}, function(data){
    if (data.done)
    {
		$('.after_add_cart').show();
    }
    else
    {
       alert(data.msg);
    }
    })
}
/*buy_now*/
function buy_now()
{
    //验证数据
	if (goodsspec.getSpec() == null)
    {
        alert(lang.select_specs);
        return;
    }
    var spec_id = goodsspec.getSpec().id;
 
    var quantity = $("#quantity").val();
    if (quantity == '')
    {
        alert(lang.input_quantity);
        return;
    }
    if (parseInt(quantity) < 1 || isNaN(quantity))
    {
        alert(lang.invalid_quantity);
        return;
    }
    buy_now_add_cart(spec_id, quantity);
}

/* add buy_now_add_cart */
function buy_now_add_cart(spec_id, quantity)
{
    var url = REAL_SITE_URL + '/index.php?app=cart&act=add';
    $.getJSON(url, {'spec_id':spec_id, 'quantity':quantity}, function(data){
		if (data.done)
        {
			location.href= REAL_SITE_URL + '/index.php?app=order&goods=cart&store_id={$goods.store_id}';
        }else{
            alert(data.msg);
        }
    });
}
var specs = new Array();
<!--{foreach from=$goods._specs item=spec}-->
specs.push(new spec({$spec.spec_id}, '{$spec.spec_1|escape}', '{$spec.spec_2|escape}', {$spec.price}, {$spec.stock}));
<!--{/foreach}-->
var specQty = {$goods.spec_qty};
var defSpec = {$goods.default_spec|escape};
var goodsspec = new goodsspec(specs, specQty, defSpec);
//]]>
</script>
<div class="goods-detail">
	<div class="col-img">
    	<div class="scroll-wrapper">
		<div id="slides" class="scroller" >
			<!--{foreach from=$goods._images item=goods_image name=fe_goods_image}-->
			<div><img src="{$site_url}/{$goods_image.thumbnail}" /></div>
        	<!--{/foreach}-->    
		</div>
		<ul class="new-banner-num new-tbl-type" id="idNum"></ul>
	</div>
    </div>
    <script>
    $(function() {
	 if($('#slides').children('div').length>1){
      	$('#slides').slidesjs({
        	width: 300,
        	height: 300,
			navigation: false,
			play: {
          	auto: false
        	}
      	});
	 }
	 	$('.handle .selected').click(function(){
		 	$(this).parent().find('.J_hidden').toggle();
			var cl = $(this).find('span').attr('class');
			if(cl == 'icon-arr')
			{
				$(this).find('span').attr('class','icon-arr-on');
			}
			else
			{
				$(this).find('span').attr('class','icon-arr');
			}
		})
		$('.change-quality em').click(function(){
			var type = $(this).attr('class');
			var _v = Number($('#quantity').val());
			var stock = Number($('*[ectype="goods_stock"]').text());
			if(type == 'plus')
			{
				if(_v > 1)
				{
					$('#quantity').val(_v-1);
				}
			}
			else if(_v < stock) {
				$('#quantity').val(_v+1);
			}else{
				alert('没有足够的商品。');
			}
		});
		
		$('.change-quality #quantity').keyup(function(){
			var _v = Number($('#quantity').val());
			var stock = Number($('*[ectype="goods_stock"]').text());
			if(_v > stock){ 
				alert('没有足够的商品。');
				$(this).val(stock);
			}
			if(_v < 1 || isNaN(_v)) {
				alert(lang.invalid_quantity);
				$(this).val(1);
			}
		});
		
		$('#J_message_box').css('left',(document.body.clientWidth-290)/2);
	});
  </script>
    
    
 	<div class="col-price clearfix">
    	<span class="float-left ml10 yahei fw-normal">{$goods.price|price}</span>
        <span class="float-right mr10"><a onclick="collect_goods({$goods.goods_id});" class="collect"></a></span>
    </div>
    
    <div class="col-title">
    	<h3><a class="fw-normal" href="#goods-detail-page" data-transition="slide">查看商品详情</a><a class="icon-arr" href="#goods-detail-page" data-transition="slide"></a></h3>
        <div class="title">
        	<span>{$goods.goods_name|escape}</span>
            <font class="red"><!--{foreach from=$goods.tags item=tag}-->{$tag}&nbsp;&nbsp;&nbsp;<!--{/foreach}--></font>
        </div>
    </div>
    <div class="line-background"></div>
    <div class="handle">
    	
            <!--{if $goods.spec_qty gt 0}-->
            <ul class="clearfix w-full J_hidden mb5">
                <li class="handle_title">{$goods.spec_name_1|escape}: </li>
            </ul>
            <!--{/if}-->
            <!--{if $goods.spec_qty gt 1}-->
            <ul class="clearfix w-full J_hidden mb5">
                <li class="handle_title">{$goods.spec_name_2|escape}: </li>
            </ul>
            <!--{/if}-->
            <ul class="clearfix w-full mb5">
                <li class="handle_title mr5" style="vertical-align:middle;">数量: </li>
                <li class="change-quality">
                	<em class="plus"><b></b></em>
                    <input type="text" class="text width1" name="" id="quantity" value="1" />
                    <em class="add"><b></b></em>
                </li>
                <span style="display:none;" ectype="goods_stock">{$goods._specs.0.stock}</span>
            </ul>
            	<!--{if $goods.spec_qty gt 0}-->
            <ul style="display:block;" class="clearfix w-full relative selected">
                <li style="display:inline-block;width:70px;" class="handle_title mr5">{$lang.your_select}: </li>
                <li style="display:inline-block;" class="aggregate" ectype="current_spec"></li>
                <span class="icon-arr"></span>
            </ul>
            <!--{/if}-->
        </div>
    <div class="line-background"></div>
    <div class="col-evaluation">
    	<div class="info">
        	<a href="{url app=goods&act=comments&id=$goods.goods_id}" class="comments clearfix">
            	<span class="text float-left">{$lang.goods_comment}</span>
                <span class="text float-right">
                	<em>{$goods.comments}</em> 人评价
                </span>
            </a>
            <span class="icon-arr"></span>
        </div>
        <div class="tbl-type">
        	<span class="tbl-cell">
            	<a href="{url app=goods&act=saleslog&id=$goods.goods_id}" class="btn-good">
                	<span class="icon"></span>
                    {$lang.sales_log}            </a>
            </span>
            <span class="tbl-cell">
            	<span class="bar">|</span>
            </span>
            <span class="tbl-cell">
            	<a href="{url app=goods&act=qa&id=$goods.goods_id}" class="btn-ser">
                	<span class="icon"></span>
                    {$lang.qa}
                </a>
            </span>
        </div>
    </div>
    <div class="enter-store">
    	<a href="{url app=store&id=$store.store_id}"><i></i>进入店铺</a>
    </div>
    <div class="interest">
    	<h3>猜你喜欢</h3>
    	<div class="content">
        	<!--{foreach from=$interest_goods item=each}-->
            <li class="clearfix">
                <!--{foreach from=$each item=igoods}-->
                <a href="{url app=goods&id=$igoods.goods_id}">
                    <dl>
                        <dt><span><img src="{$igoods.default_image}" /></span></dt>
                        <dd>
                        	<p class="name">{$igoods.goods_name|escape}</p>
                            <p class="price">{$igoods.price|price}</p>
                       </dd>
                    </dl>
                </a>
                <!--{/foreach}-->
            </li>
            <!--{/foreach}-->
    	</ul>
    </div>
</div>
</div>
<div class="after_add_cart">
	<div class="message-box" id="J_message_box">
        <div class="tips">
           <b>添加成功</b>
           <span>商品已成加入购物车！</span>
        </div>
		<div class="continus2buy">
        	<a href="javascript:;" onclick="$('.after_add_cart').hide();">再逛逛</a>
            <a href="{url app=cart}">去购物车</a>
        </div>
	</div>
    <div class="masker"></div>
</div>